/**
 * 饼图
 */
import React  from 'react'
import style from './index.less'
import {IECharts} from '../../../../components'

const PieCharts=({data})=>{
	const symbolMap = {};
  data.forEach((item) => {
    if (symbolMap[item.symbol] === undefined) {
      symbolMap[item.symbol] = item.price * item.quantity;
    } else {
      symbolMap[item.symbol] += item.price * item.quantity;
    }
  });

  const pieData = [];
  for (const name in symbolMap) {
    pieData.push({ value: symbolMap[name].toFixed(2), name });
  }

  pieData.sort((a, b) => (a.value - b.value));

	const myProps={
		option : {

    tooltip : {
        trigger: 'item',
        formatter: "{b} : {c} ({d}%)",
				confine:true
    },

    series : [
        {
            name: '',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:pieData,
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
}
	}
  return(
    <div  className={`chart`} style={{height:300}}>
      <IECharts {...myProps} resizable={true}/>
    </div>
  )
}

PieCharts.propTypes={
	// data
}

export default PieCharts
